



<!doctype html>
<html lang="en" class="no-js">
  <head>

<style>
  h1, h2, h3 { color: #04A9F4; }
  pre { color: black !important; }
</style>


      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      <meta http-equiv="x-ua-compatible" content="ie=edge">

        <meta name="description" content="Open source package for Survival Analysis modeling">


        <link rel="canonical" href="https://www.pysurvival.io/models/survival_forest.html">


        <meta name="author" content="The PySurvival Team">


        <meta name="lang:clipboard.copy" content="Copy to clipboard">

        <meta name="lang:clipboard.copied" content="Copied to clipboard">

        <meta name="lang:search.language" content="en">

        <meta name="lang:search.pipeline.stopwords" content="True">

        <meta name="lang:search.pipeline.trimmer" content="True">

        <meta name="lang:search.result.none" content="No matching documents">

        <meta name="lang:search.result.one" content="1 matching document">

        <meta name="lang:search.result.other" content="# matching documents">

        <meta name="lang:search.tokenizer" content="[\s\-]+">

      <link rel="shortcut icon" href="../images/favicon.ico">
      <meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.0.2">



        <title>Theory - PySurvival</title>



      <link rel="stylesheet" href="../assets/stylesheets/application.982221ab.css">

        <link rel="stylesheet" href="../assets/stylesheets/application-palette.224b79ff.css">




        <meta name="theme-color" content="#2196f3">



      <script src="../assets/javascripts/modernizr.1f0bcf2b.js"></script>



        <link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=:300,400,400i,700|">
        <style>body,input{font-family:"","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"","Courier New",Courier,monospace}</style>


    <link rel="stylesheet" href="../assets/fonts/material-icons.css">






  </head>



    <body dir="ltr" data-md-color-primary="blue" data-md-color-accent="purple">

    <svg class="md-svg">
      <defs>


          <svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
    viewBox="0 0 416 448" id="__github">
  <path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
        8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
        18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
        19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
        18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
        304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
        2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
        38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
        37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
        82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
        1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
        0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
        30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
        46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
        99.5z" />
</svg>

      </defs>
    </svg>
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" data-md-component="overlay" for="__drawer"></label>

      <a href="#survival-forest-models" tabindex="1" class="md-skip">
        Skip to content
      </a>


      <header class="md-header" data-md-component="header">
  <nav class="md-header-nav md-grid">
    <div class="md-flex">
      <div class="md-flex__cell md-flex__cell--shrink">
        <a href="https://www.pysurvival.io/" title="PySurvival" class="md-header-nav__button md-logo">

            <img src="../images/logo.ico" width="24" height="24">

        </a>
      </div>
      <div class="md-flex__cell md-flex__cell--shrink">
        <label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
      </div>
      <div class="md-flex__cell md-flex__cell--stretch">
        <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">

            <span class="md-header-nav__topic">
              PySurvival
            </span>
            <span class="md-header-nav__topic">
              Theory
            </span>

        </div>
      </div>

              <!-- Global site tag (gtag.js) - Google Analytics -->
              <script async src="https://www.googletagmanager.com/gtag/js?id=UA-136790579-1"></script>
              <script>
                window.dataLayer = window.dataLayer || [];
                function gtag(){dataLayer.push(arguments);}
                gtag('js', new Date());

                gtag('config', 'UA-136790579-1');
              </script>

      <div class="md-flex__cell md-flex__cell--shrink">

          <label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>

<div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
      <label class="md-icon md-search__icon" for="__search"></label>
      <button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
        &#xE5CD;
      </button>
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="result">
          <div class="md-search-result__meta">
            Type to start searching
          </div>
          <ol class="md-search-result__list"></ol>
        </div>
      </div>
    </div>
  </div>
</div>

      </div>

        <div class="md-flex__cell md-flex__cell--shrink">
          <div class="md-header-nav__source">





<a href="https://github.com/square/pysurvival/" title="Go to repository" class="md-source" >

    <div class="md-source__icon">
      <svg viewBox="0 0 24 24" width="24" height="24">
        <use xlink:href="#__github" width="24" height="24"></use>
      </svg>
    </div>

  <div class="md-source__repository">
    square/pysurvival
  </div>
</a>
          </div>
        </div>

    </div>
  </nav>
</header>

    <div class="md-container">




      <main class="md-main">
        <div class="md-main__inner md-grid" data-md-component="container">


              <div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    <nav class="md-nav md-nav--primary" data-md-level="0">
  <label class="md-nav__title md-nav__title--site" for="__drawer">
    <a href="https://www.pysurvival.io/" title="PySurvival" class="md-nav__button md-logo">

        <img src="../images/logo.ico" width="48" height="48">

    </a>
    PySurvival
  </label>

    <div class="md-nav__source">





<a href="https://github.com/square/pysurvival/" title="Go to repository" class="md-source" >

    <div class="md-source__icon">
      <svg viewBox="0 0 24 24" width="24" height="24">
        <use xlink:href="#__github" width="24" height="24"></use>
      </svg>
    </div>

  <div class="md-source__repository">
    square/pysurvival
  </div>
</a>
    </div>

  <ul class="md-nav__list" data-md-scrollfix>






  <li class="md-nav__item">
    <a href="../index.html" title="Home" class="md-nav__link">
      Home
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../installation.html" title="Installation" class="md-nav__link">
      Installation
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../intro.html" title="Introduction to Survival Analysis" class="md-nav__link">
      Introduction to Survival Analysis
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../math.html" title="The math of Survival Analysis" class="md-nav__link">
      The math of Survival Analysis
    </a>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-5" type="checkbox" id="nav-5">

    <label class="md-nav__link" for="nav-5">
      Tutorials
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-5">
        Tutorials
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="../tutorials/churn.html" title="Churn Prediction" class="md-nav__link">
      Churn Prediction
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../tutorials/credit_risk.html" title="Credit Risk" class="md-nav__link">
      Credit Risk
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../tutorials/employee_retention.html" title="Employee Retention" class="md-nav__link">
      Employee Retention
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../tutorials/maintenance.html" title="Predictive Maintenance" class="md-nav__link">
      Predictive Maintenance
    </a>
  </li>


      </ul>
    </nav>
  </li>









  <li class="md-nav__item md-nav__item--active md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6" type="checkbox" id="nav-6" checked>

    <label class="md-nav__link" for="nav-6">
      Models
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-6">
        Models
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-1" type="checkbox" id="nav-6-1">

    <label class="md-nav__link" for="nav-6-1">
      Cox Proportional Hazard
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-1">
        Cox Proportional Hazard
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="coxph.html" title="Standard CoxPH  (API)" class="md-nav__link">
      Standard CoxPH  (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="nonlinear_coxph.html" title="DeepSurv/Nonlinear CoxPH (API)" class="md-nav__link">
      DeepSurv/Nonlinear CoxPH (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="semi_parametric.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-2" type="checkbox" id="nav-6-2">

    <label class="md-nav__link" for="nav-6-2">
      Multi-Task Logistic Regression (MTLR)
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-2">
        Multi-Task Logistic Regression (MTLR)
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="linear_mtlr.html" title="Linear MTLR (API)" class="md-nav__link">
      Linear MTLR (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="neural_mtlr.html" title="Neural MTLR (API)" class="md-nav__link">
      Neural MTLR (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="mtlr_theory.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-3" type="checkbox" id="nav-6-3">

    <label class="md-nav__link" for="nav-6-3">
      Non-Parametric
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-3">
        Non-Parametric
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="kaplan_meier.html" title="Kaplan Meier (API)" class="md-nav__link">
      Kaplan Meier (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="smooth_kaplan_meier.html" title="Smoothed Kaplan Meier (API)" class="md-nav__link">
      Smoothed Kaplan Meier (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="non_parametric.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-4" type="checkbox" id="nav-6-4">

    <label class="md-nav__link" for="nav-6-4">
      Parametric
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-4">
        Parametric
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="parametric.html" title="Parametric models (API)" class="md-nav__link">
      Parametric models (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="parametric_theory.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-5" type="checkbox" id="nav-6-5">

    <label class="md-nav__link" for="nav-6-5">
      Simulation
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-5">
        Simulation
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="simulations.html" title="Simulation models (API)" class="md-nav__link">
      Simulation models (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="simulations_theory.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>









  <li class="md-nav__item md-nav__item--active md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-6" type="checkbox" id="nav-6-6" checked>

    <label class="md-nav__link" for="nav-6-6">
      Survival Forest
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-6">
        Survival Forest
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="conditional_survival_forest.html" title="Conditional Survival Forest (API)" class="md-nav__link">
      Conditional Survival Forest (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="extra_survival_trees.html" title="Extra Survival Trees (API)" class="md-nav__link">
      Extra Survival Trees (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="random_survival_forest.html" title="Random Survival Forest (API)" class="md-nav__link">
      Random Survival Forest (API)
    </a>
  </li>









  <li class="md-nav__item md-nav__item--active">

    <input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">




      <label class="md-nav__link md-nav__link--active" for="__toc">
        Theory
      </label>

    <a href="survival_forest.html" title="Theory" class="md-nav__link md-nav__link--active">
      Theory
    </a>


<nav class="md-nav md-nav--secondary">





    <label class="md-nav__title" for="__toc">Table of contents</label>
    <ul class="md-nav__list" data-md-scrollfix>

        <li class="md-nav__item">
  <a href="#general-algorithm" title="General algorithm" class="md-nav__link">
    General algorithm
  </a>

</li>

        <li class="md-nav__item">
  <a href="#random-survival-forest-model" title="Random Survival Forest model" class="md-nav__link">
    Random Survival Forest model
  </a>

</li>

        <li class="md-nav__item">
  <a href="#extremely-randomized-extra-survival-trees-model" title="Extremely Randomized (Extra) Survival Trees model" class="md-nav__link">
    Extremely Randomized (Extra) Survival Trees model
  </a>

</li>

        <li class="md-nav__item">
  <a href="#conditional-survival-forest-model" title="Conditional Survival Forest model" class="md-nav__link">
    Conditional Survival Forest model
  </a>

</li>

        <li class="md-nav__item">
  <a href="#references" title="References" class="md-nav__link">
    References
  </a>

</li>





    </ul>

</nav>

  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-6-7" type="checkbox" id="nav-6-7">

    <label class="md-nav__link" for="nav-6-7">
      Survival SVM
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="2">
      <label class="md-nav__title" for="nav-6-7">
        Survival SVM
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="linear_svm.html" title="Linear Survival SVM (API)" class="md-nav__link">
      Linear Survival SVM (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="kernel_svm.html" title="Kernel Survival SVM (API)" class="md-nav__link">
      Kernel Survival SVM (API)
    </a>
  </li>







  <li class="md-nav__item">
    <a href="survival_svm.html" title="Theory" class="md-nav__link">
      Theory
    </a>
  </li>


      </ul>
    </nav>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-7" type="checkbox" id="nav-7">

    <label class="md-nav__link" for="nav-7">
      Performance metrics
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-7">
        Performance metrics
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="../metrics/c_index.html" title="C-index" class="md-nav__link">
      C-index
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../metrics/brier_score.html" title="Brier Score" class="md-nav__link">
      Brier Score
    </a>
  </li>


      </ul>
    </nav>
  </li>







  <li class="md-nav__item md-nav__item--nested">

      <input class="md-toggle md-nav__toggle" data-md-toggle="nav-8" type="checkbox" id="nav-8">

    <label class="md-nav__link" for="nav-8">
      Miscellaneous
    </label>
    <nav class="md-nav" data-md-component="collapsible" data-md-level="1">
      <label class="md-nav__title" for="nav-8">
        Miscellaneous
      </label>
      <ul class="md-nav__list" data-md-scrollfix>







  <li class="md-nav__item">
    <a href="../miscellaneous/activation_functions.html" title="Activation Functions" class="md-nav__link">
      Activation Functions
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../miscellaneous/save_load.html" title="Saving/Loading models" class="md-nav__link">
      Saving/Loading models
    </a>
  </li>







  <li class="md-nav__item">
    <a href="../miscellaneous/tips.html" title="Tips for fitting models" class="md-nav__link">
      Tips for fitting models
    </a>
  </li>


      </ul>
    </nav>
  </li>


  </ul>
</nav>
                  </div>
                </div>
              </div>


              <div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">

<nav class="md-nav md-nav--secondary">





    <label class="md-nav__title" for="__toc">Table of contents</label>
    <ul class="md-nav__list" data-md-scrollfix>

        <li class="md-nav__item">
  <a href="#general-algorithm" title="General algorithm" class="md-nav__link">
    General algorithm
  </a>

</li>

        <li class="md-nav__item">
  <a href="#random-survival-forest-model" title="Random Survival Forest model" class="md-nav__link">
    Random Survival Forest model
  </a>

</li>

        <li class="md-nav__item">
  <a href="#extremely-randomized-extra-survival-trees-model" title="Extremely Randomized (Extra) Survival Trees model" class="md-nav__link">
    Extremely Randomized (Extra) Survival Trees model
  </a>

</li>

        <li class="md-nav__item">
  <a href="#conditional-survival-forest-model" title="Conditional Survival Forest model" class="md-nav__link">
    Conditional Survival Forest model
  </a>

</li>

        <li class="md-nav__item">
  <a href="#references" title="References" class="md-nav__link">
    References
  </a>

</li>





    </ul>

</nav>
                  </div>
                </div>
              </div>


          <div class="md-content">
            <article class="md-content__inner md-typeset">


                  <a href="https://github.com/square/pysurvival/edit/master/docs/models/survival_forest.md" title="Edit this page" class="md-icon md-content__icon">&#xE3C9;</a>


                <!-- # Survival Forest models-->

<style>
  h1, h2, h3 { color: #04A9F4; }
</style>

<h1 id="survival-forest-models">Survival Forest models</h1>
<p>The Ensemble models that use decision trees as its base learners can be extended to take into account censored datasets. These types of models can be regrouped under the name <strong>Survival Forest models</strong>. PySurvival contains 3 types of Survival Forest models:</p>
<ul>
<li>Random Survival Forest model (<a href="random_survival_forest.html"><code>RandomSurvivalForestModel</code></a>)</li>
<li>Extremely Randomized (Extra) Survival Trees model (<a href="extra_survival_trees.html"><code>ExtraSurvivalTreesModel</code></a>)</li>
<li>Conditional Survival Forest model (<a href="conditional_survival_forest.html"><code>ConditionalSurvivalForestModel</code></a>)</li>
</ul>
<p>These models have been adapted to python from the package <a href="https://arxiv.org/pdf/1508.04409.pdf">ranger</a>, which is a fast implementation of random forests in C++.</p>
<hr />
<h2 id="general-algorithm">General algorithm</h2>
<p><a href="https://arxiv.org/pdf/0811.1645.pdf">Ishwaran et al.</a> provides a general framework that can be used to describe the underlying algorithm that powers  the Survival Forest models:</p>
<ol>
<li>
<p>Draw <script type="math/tex">B</script> random samples of the same size from the original dataset with replacement. The samples that are not
drawn are said to be out-of-bag (OOB).</p>
</li>
<li>
<p>Grow a survival tree on each of the <script type="math/tex">b = 1, ..., B</script> samples. </p>
<p><strong>a.</strong> At each node, select a random subset of predictor variables and find the best
predictor and splitting value that provide two subsets (the daughter nodes)
which maximizes the difference in the objective function.</p>
<p><strong>b.</strong> Repeat <strong>a.</strong> recursively on each daughter node until a stopping criterion is met.</p>
</li>
<li>
<p>Calculate a cumulative hazard function (CHF) for each tree and average over all CHFs
for the B trees to obtain the ensemble CHF.</p>
</li>
<li>
<p>Compute the prediction error for the ensemble CHF using only the OOB data.</p>
</li>
</ol>
<p>All the Survival Forest models in PySurvival use this framework as the basis of the model fitting algorithm. The objective function is the main element that can differentiate then from one another.</p>
<hr />
<h2 id="random-survival-forest-model"><a href="random_survival_forest.html">Random Survival Forest model</a></h2>
<p>At each node, we choose a predictor <strong><script type="math/tex">x</script></strong> from a subset of randomly selected predictor variables and a split value <strong><script type="math/tex">c</script></strong>.
<strong><script type="math/tex">c</script></strong> is one of the unique values of <strong><script type="math/tex">x</script></strong></p>
<p>We assign each individual sample <script type="math/tex">i</script> to either the right node, if <script type="math/tex">x_i \leq c</script> or left daughter node if <script type="math/tex">x_i > c</script>.
Then we calculate the value of the log rank test such that:</p>
<p>
<script type="math/tex; mode=display">\begin{equation}
L(x, c) = \frac{ \sum^{N}_{i=1} \left(  d_{i, 1} - Y_{i,1} \frac{d_i}{Y_i} \right)  }
               { \sqrt{  \sum^{N}_{i=1}  \frac{Y_{i,1}}{Y_i} \left( 1 - \frac{Y_{i,1}}{Y_i} \right) \left( \frac{Y_i-d_i}{Y_i-1} \right) d_i  } }
\end{equation}</script>
</p>
<p>with:</p>
<ul>
<li>
<script type="math/tex">j</script>: Daughter node, <script type="math/tex">j \in \{1, 2\}</script>
</li>
<li>
<script type="math/tex">d_{i,j}</script> : Number of events at time <script type="math/tex">t_i</script> in daughter node <script type="math/tex">j</script>.</li>
<li>
<script type="math/tex">Y_{i,j}</script> : Number of units that experienced an event or are at risk at time <script type="math/tex">t_i</script> in daughter node <script type="math/tex">j</script>.</li>
<li>
<script type="math/tex">d_i</script> : Number of events at time <script type="math/tex">t_i</script>, so <script type="math/tex">d_i=\sum_j d_{i,j}</script>
</li>
<li>
<script type="math/tex">Y_i</script> : Number of units that experienced an event or at risk at time <script type="math/tex">t_i</script>, so <script type="math/tex">Y_i=\sum_j Y_{i,j}</script>
</li>
</ul>
<p>We loop through every <strong><script type="math/tex">x</script></strong> and <strong><script type="math/tex">c</script></strong> until we find <script type="math/tex">x^{*}</script> and <script type="math/tex">c^{*}</script> that satisfy <script type="math/tex">|L(x^{*}, c^{*})| \geq |L(x, c)|</script> for
every <script type="math/tex">x</script> and <script type="math/tex">c</script>.</p>
<hr />
<h2 id="extremely-randomized-extra-survival-trees-model"><a href="extra_survival_trees.html">Extremely Randomized (Extra) Survival Trees model</a></h2>
<p>Extra Survival Trees models use the same objective function as the Random Survival Forest models. But for each predictor <strong><script type="math/tex">x</script></strong>, instead of using the unique values of <strong><script type="math/tex">x</script></strong> to find the best split value <script type="math/tex">c^{*}</script>, we use <script type="math/tex">N_{splits}</script> values drawn from a uniform distribution over the interval <script type="math/tex">\left[\min(x), \max(x)\right]</script>.</p>
<hr />
<h2 id="conditional-survival-forest-model"><a href="conditional_survival_forest.html">Conditional Survival Forest model</a></h2>
<p>Conditional Survival Forest models are constructed in a way that is a bit different from Random Survival Forest models:</p>
<ol>
<li>
<p>The objective function is given by testing the null hypothesis that there is independence between
the response and the predictor. To do so, for each predictor variable <script type="math/tex">x</script>, compute the logrank score test statistic and its associated p-value:</p>
<ul>
<li>
<p>Let's consider <script type="math/tex">n</script> observations <script type="math/tex">(T_1, \delta_1), ... , (T_n, \delta_n)</script>. We will assume the predictor <script type="math/tex">x</script> has been ordered so that <script type="math/tex">x_1 \leq x_2 \leq ... \leq x_n</script>. With <script type="math/tex">\gamma_j = \sum^n_{i=1} 1_{T_i \leq T_j}</script>, we compute the logrank scores <script type="math/tex">a_1, ..., a_n</script> such that :</p>
<p>
<script type="math/tex; mode=display">\begin{equation}
a_i = \delta_i - \sum^{\gamma_i}_{j=1} \frac{\delta_j}{(n-\gamma_j + 1)}
\end{equation}</script>
</p>
</li>
<li>
<p>For a predictor <script type="math/tex">x</script> and split value <script type="math/tex">c</script>, and within the right node (<script type="math/tex">x_i \leq c</script>), we can now calculate :</p>
<ul>
<li>the sum of all scores <script type="math/tex">S_{n, c} = \sum_{i=1}^n 1_{x_i \leq c} \cdot a_i</script>
</li>
<li>its expectation <script type="math/tex">\text{E}\left[ S_{n, c} \right] = m_c \cdot \overline{a}</script>  with  <script type="math/tex">m_c=\sum_{i=1}^n 1_{x_i \leq c}</script> and <script type="math/tex">\overline{a}=\frac{1}{n}\sum_{i=1}^n a_i</script>
</li>
<li>its variance <script type="math/tex">\text{Var}\left[ S_{n, c} \right] = \frac{m_c n_c}{n(n-1)} \sum_{i=1}^n \left( a_i - \overline{a} \right)^2</script>  with <script type="math/tex">n_c = n-m_c</script>
</li>
</ul>
</li>
<li>
<p>We can obtain the score test statistic <script type="math/tex">T_{n,c} = \frac{ S_{n, c} - \text{E}\left[ S_{n, c} \right] }{ \sqrt{\text{Var}\left[ S_{n, c} \right] } }</script> and look for <script type="math/tex">c^{*}</script> such that <script type="math/tex">|T_{n, c^{*}}| \geq |T_{n, c}|</script>.</p>
</li>
<li>
<p>Finally, we compute the p-value associated with <script type="math/tex">T_{n, c^{*}}</script>.</p>
</li>
</ul>
</li>
<li>
<p>At each node, only for the predictors whose associated p-value is smaller than a specified value <script type="math/tex">\alpha</script>, the predictor with the smallest p-value is selected as splitting candidate. However, if no predictor can be used then no split is performed.</p>
</li>
</ol>
<h2 id="references">References</h2>
<ul>
<li><a href="https://arxiv.org/pdf/0811.1645.pdf">Ishwaran H, Kogalur U, Blackstone E, Lauer M. Random survival forests. The Annals of Applied
Statistics. 2008; 2(3):841–860.</a></li>
<li><a href="https://arxiv.org/pdf/1508.04409.pdf">ranger: A Fast Implementation of Random Forests for High Dimensional Data in C++ and R</a></li>
<li><a href="https://digitalcommons.usu.edu/gradreports/927">Weathers, Brandon and Cutler, Richard Dr., "Comparison of Survival Curves Between Cox Proportional Hazards, Random Forests, and Conditional Inference Forests in Survival Analysis" (2017). All Graduate Plan B and other Reports. 927.</a></li>
<li><a href="https://arxiv.org/pdf/1605.03391.pdf">Wright, Marvin N., Theresa Dankowski and Andreas Ziegler. "Random forests for survival analysis using maximally selected rank statistics."" Statistics in medicine 36 8 (2017): 1272-1284.</a></li>
<li><a href="https://link.springer.com/content/pdf/10.1007/s10994-006-6226-1.pdf">Geurts, Pierre &amp; Ernst, Damien &amp; Wehenkel, Louis. (2006). Extremely Randomized Trees. Machine Learning. 63. 3-42. 10.1007/s10994-006-6226-1.</a></li>
</ul>









            </article>
          </div>
        </div>
      </main>


<footer class="md-footer">

  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-footer-copyright">

          <div class="md-footer-copyright__highlight">
            Copyright &copy; 2019 Square Inc.
          </div>



        brought to you by
        <a href="https://squareup.com/us">
        <img src="images/Square_logo.png" alt="Square Logo" title="Square Logo" width=20%, height=20% align="center"  /></a>


      </div>

  <div class="md-footer-social">
    <link rel="stylesheet" href="../assets/fonts/font-awesome.css">

      <a href="https://pysurvival.io/" class="md-footer-social__link fa fa-home"></a>

      <a href="https://github.com/square/pysurvival" class="md-footer-social__link fa fa-github"></a>

  </div>

    </div>
  </div>
</footer>

    </div>

      <script src="../assets/javascripts/application.d9aa80ab.js"></script>

      <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>

        <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML"></script>

        <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/0.5.7/chartjs-plugin-annotation.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>


  </body>
</html>
